// 1、上传一张图片
$("#file").on("change", function () {
  var file = this.files[0];
  var form = new FormData();
  form.append("rotaImg", file);
  $.ajax({
    type: "post",
    url: "/upload",
    data: form,
    processData: false,
    contentType: false,
    success: (res) => {
      // console.log(res);
      // res[0].rotaImg
      $("#rotaimg").val(res[0].rotaImg);
      $("#rImg").prop("src", res[0].rotaImg);
    },
  });
});

// 添加
$("#addRota").on("submit", function () {
  var form = $(this).serialize();
  console.log("轮播图表单内容：", form);
  $.ajax({
    type: "post",
    url: "/slides",
    data: form,
    success: (res) => {
      // console.log(res);
      location.reload();
    },
  });
  return false;
});

// 2、获取轮播图列表
$.ajax({
    type:'get',
    url:'/slides',
    success:res=>{
        console.log(res);
        var html = template('rotaImgTpl',{data:res})
        $('tbody').html(html)
    }
})

// 3、删除轮播图
$('tbody').on('click','.deleteBtn',function(){
    alert('删除操作...')
    var id = $(this).attr('data-id')
    $.ajax({
        type:'delete',
        url:`/slides/${id}`,
        success:res=>{
            // console.log('被删除轮播图：',res);
            location.reload();
        }
    })
})